//
//  FamilyMedicalRecordDetialInfoViewController.m
//  安好
//
//  Created by lianchuang on 14-12-11.
//  Copyright (c) 2014年 lianchuangbrother. All rights reserved.
//

#import "FamilyMedicalRecordDetialInfoViewController.h"
//病历modal
#import "FamilyMedicalVisitModal.h"
//病历标题--病症
#import "FamilyMedicalRecordFirstCell.h"
//医生图片--医生职称名字
#import "FamilyMedicalRecordDoctorCell.h"
//诊断结果--
#import "FamilyLastPicCell.h"
//段头
#import "FamilyRecordSectionHeaderView.h"
#import "FamilyMedicalTitleCell.h"
#import "FamilyMedicalProblemCell.h"
//医生详情
#import "DocInfoViewController.h"
#define LineColor [UIColor colorWithRed:221/255.0 green:221/255.0 blue:221/255.0 alpha:1];

#define IPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)

@interface FamilyMedicalRecordDetialInfoViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
//控制行--加载cell
@property (nonatomic, strong) NSMutableArray *dataArray;
/**
 *  接收网络请求回来的数据，初诊，复诊
 */
@property(nonatomic,strong)NSMutableArray * visitDataArray;
/**
 *  控制初诊复诊的开合@“0”关@“1”开
 */
@property(nonatomic,strong)NSMutableArray * sectionFlagArray;
//保存旧的开启的标至
@property(nonatomic,assign)NSInteger oldFlag;
@end

@implementation FamilyMedicalRecordDetialInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadData];
    [self makeNavBar];
    [self makeTableView];
    [self AFNetGetFamilyMedicalRecord];
    
}
#pragma mark - 导航条
-(void)makeNavBar
{
    self.navigationItem.title = @"家人病历";
    // 返回按钮图片
    UIBarButtonItem *backBtnImg = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"公用_返回.png"] style:UIBarButtonItemStylePlain target:self action:@selector(backBtnClicked)];
    backBtnImg.tintColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = backBtnImg;
    
    
}
-(void)backBtnClicked
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)loadData{
    self.dataArray = [NSMutableArray arrayWithCapacity:0];
    self.visitDataArray =[NSMutableArray arrayWithCapacity:0];
    self.sectionFlagArray = [NSMutableArray arrayWithCapacity:0];
    
    [self.dataArray addObject:@"病历标题:0段"];
    [self.dataArray addObject:@"医生姓名和图片:1段"];
}

#pragma mark - AFNet获取具体病历--查看病历
-(void)AFNetGetFamilyMedicalRecord
{
    [self showActionView];
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];//case/check/
    NSString * getUrl = [NSString stringWithFormat:@"%@case/check/",kBaseURL];
    NSDictionary * parameters = @{@"platform":kPlatform,@"version":kVersion,@"caseid":self.userCaseModel.caseid};
    
    [manager GET:getUrl parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        MyNSLog("成功");
        [self hiddenActionView];
        
        NSNumber * statusNum = [responseObject objectForKey:@"status"];
        NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
        NSString * statusString = [numberFormatter stringFromNumber:statusNum];
        if ([statusString isEqualToString:@"0"]) {
            [self shouLabel:@"暂无病历内容"];
        }
        else//成功
        {
            NSArray * visitArray = responseObject[@"data"];
            for (NSDictionary * dic in visitArray) {
                FamilyMedicalVisitModal * modal = [[FamilyMedicalVisitModal alloc] initWithDic:dic];
                modal.medicalDescription = dic[@"description"];
                [self.visitDataArray addObject:modal];
                [self.sectionFlagArray addObject:@"0"];
            }
            self.oldFlag = 100+self.visitDataArray.count+10;
            [self.tableView reloadData];
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        MyNSLog("失败");
        [self hiddenActionView];
        
    }];

}

#pragma mark - 创建tableView
-(void)makeTableView
{
    // 搭建UITableView
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-iOS7TopMargin) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [ClassMethodsViewController colorWithHexString:BACK_BACKGROUNDCOLOR_16];
    //隐藏横向和竖向的滑条
    self.tableView.showsHorizontalScrollIndicator = NO;
    self.tableView.showsVerticalScrollIndicator = NO;
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.view addSubview:self.tableView];
    
}
//段头视图 -- 收缩状态下只显示段头
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (self.visitDataArray.count != 0)
    {
        if (section > 1) {
            CGFloat height = 44;
            if (IPhone6Plus) {
                height = 53;
            }
            FamilyRecordSectionHeaderView * headerView =[[FamilyRecordSectionHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, height)];
            
            
            FamilyMedicalVisitModal * modal = self.visitDataArray[section-2];
            if (section == 2) {
                headerView.FamilyHeaderTitleLable.text = @"初诊";
                headerView.FamilyTimeLable.text = modal.clinictime;
                headerView.FamilyHeaderButton.tag = 100 + section-2;
                [headerView.FamilyHeaderButton addTarget:self action:@selector(openCloseButtonDown:) forControlEvents:UIControlEventTouchUpInside];
                headerView.topLineImg.backgroundColor = LineColor;
                headerView.bottomLineImg.backgroundColor = LineColor;
                headerView.bottomLineImg.frame = CGRectMake(15, headerView.height-0.5, kScreenWidth-15, 0.5);
                if (IPhone6Plus) {
                    headerView.bottomLineImg.left = 20;
                }
            }else
            {
                headerView.FamilyHeaderTitleLable.text = @"复诊";
                
                headerView.FamilyTimeLable.text = modal.clinictime;
                MyNSLog("%@", modal.clinictime);
                headerView.FamilyHeaderButton.tag = 100 + section-2;
                [headerView.FamilyHeaderButton addTarget:self action:@selector(openCloseButtonDown:) forControlEvents:UIControlEventTouchUpInside];
                headerView.bottomLineImg.backgroundColor = LineColor;
                headerView.bottomLineImg.frame = CGRectMake(15, headerView.height-0.5, kScreenWidth-15, 0.5);
                if (IPhone6Plus) {
                    headerView.bottomLineImg.left = 20;
                }
            }
            if (section== self.visitDataArray.count+1 && [self.sectionFlagArray[section-2] intValue] == 0 ) {
                
                [UIView animateWithDuration:0.35 animations:^{
                     headerView.bottomLineImg.frame = CGRectMake(0, headerView.height-0.5, kScreenWidth, 0.5);
                }];
               
            }
            if ([self.sectionFlagArray[section-2] intValue] != 0) {
                headerView.FamilyTimeBackView.hidden = YES;
            }
  
            return headerView;
        }else
        {
            return nil;
        }
        
    }
    else
    {
        return nil;
    }
}
-(void)openCloseButtonDown:(UIButton*)button
{
   
    if (self.oldFlag > 100+self.visitDataArray.count) {
        [self.sectionFlagArray replaceObjectAtIndex:button.tag-100 withObject:@"1"];
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:button.tag-100+2] withRowAnimation:UITableViewRowAnimationFade];
        [self scrollToRowAtLastSecionWithLastIndexPathWithSection:button.tag-100+2];
        self.oldFlag = button.tag;
    }else
    {
        if (button.tag != self.oldFlag) {
        
            [self.sectionFlagArray replaceObjectAtIndex:self.oldFlag-100 withObject:@"0"];
            
            [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:self.oldFlag-100+2] withRowAnimation:UITableViewRowAnimationFade];
            [self.sectionFlagArray replaceObjectAtIndex:button.tag-100 withObject:@"1"];
            [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:button.tag-100+2] withRowAnimation:UITableViewRowAnimationFade];
            [self scrollToRowAtLastSecionWithLastIndexPathWithSection:button.tag-100+2];
             self.oldFlag = button.tag;
        }else
        {
        
            [self.sectionFlagArray replaceObjectAtIndex:button.tag-100 withObject:@"0"];
            [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:button.tag-100+2] withRowAnimation:UITableViewRowAnimationFade];
            self.oldFlag = 100+self.visitDataArray.count+10;
        
        }
    
    }
 
}
//段头高
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    //第0段 和 第1段 段头高10/12
    if (section == 0 || section == 1) {
        if (IPhone6Plus) {
            return 12;
        }else{
            return 10;
        }
    }else//段头--其他段的段头和行高一样
    {
        if (IPhone6Plus) {
            return 53;
        }else{
            return 44;
        }
    }
}
//段尾的高
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    //只有第一段的段尾高
    if (section == 1) {
        if (IPhone6Plus) {
            return 12;
        }else{
            return 10;
        }
    }else
    {
        return 0.01;
    }
}

//各段有多少行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 1||section == 0) {
        return 1;
    }
    else//开始判断
    {
        if ([self.sectionFlagArray[section-2] intValue]==0) {
           
            return 0;
        }else
        {
            return 5;
            
        }
    }
}
//多少段
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2+self.visitDataArray.count;
}
//各行的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat fontSize = 13.f;
    CGFloat cellHeight = 44;
    if (IPhone6Plus) {
        fontSize = 15.f;
        cellHeight = 53;
    }
    
    
    //第0段 - 只有1行 - 病历标题
    if (indexPath.section == 0) {
        if (IPhone6Plus) {
            return 53;
        }else{
            return 44;
        }
    }
    //第1段 只有1行 - 医生头像，名字|科室 信息
    else if (indexPath.section == 1){
        if (IPhone6Plus) {
            return 78;
        }else{
            return 65;
        }
    }
    //第2段是病历详情段
    else {
        FamilyMedicalVisitModal * visitModal = self.visitDataArray[indexPath.section-2];
        //第0，1，3行是 标题行 - “就诊时间”“患者问题”“医生诊断”
        if (indexPath.row == 0 || indexPath.row == 1 || indexPath.row == 3 ) {
            if (IPhone6Plus) {
                return 53;
            }else{
                return 44;
            }
        }
        //第2行 - 是患者问题的详细描述
        else if (indexPath.row == 2) {

            FamilyMedicalProblemCell * cell = (FamilyMedicalProblemCell*)[self tableView:tableView cellForRowAtIndexPath:indexPath];
            //问题文本需要多高
            CGFloat height = [self autosizeFontAndSizeForTextString:visitModal.medicalDescription WithLableWeight:cell.FamilyProblemLable.width AndTextFont:fontSize];
            if (cellHeight - 20 >=height) {
                return cellHeight;
            }else{
                return height+26;
            }
            
        }
        //第4行是医生诊断的最后结果的描述
        else if (indexPath.row == 4){
            FamilyLastPicCell * cell = (FamilyLastPicCell*)[self tableView:tableView cellForRowAtIndexPath:indexPath];
            
            CGFloat height = [self autosizeFontAndSizeForTextString:visitModal.diagnose WithLableWeight:cell.doctorResultLable.width AndTextFont:fontSize];
            
            //有图片
            if (visitModal.pic.count != 0) {
                
                return cell.doctorResultPicBackView.bottom+13;
                
                
            }else
            {
                if (cellHeight - 20 >=height) {
                    return cellHeight;
                }else{
                    return height+26;
                }
                
            }
            
        }
        else
        {
            return 0;
        }
    }
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //病历标题
    if (indexPath.section == 0) {
        FamilyMedicalRecordFirstCell * cell = [tableView dequeueReusableCellWithIdentifier:@"TitleCell"];
        CGFloat viewLeft = 15;
        if (cell == nil) {
            if (IPhone6Plus) {
                cell = [[[NSBundle mainBundle] loadNibNamed:@"FamilyMedicalRecordFirstCell" owner:self options:nil] lastObject];
                viewLeft = 20;
            }else{
                cell = [[[NSBundle mainBundle] loadNibNamed:@"FamilyMedicalRecordFirstCell" owner:self options:nil] firstObject];
            }
        }
        cell.FamilyTitleLable.text = @"病历标题";
        cell.FamilyDetialInfoLable.text = self.userCaseModel.title;
        cell.topLineImg.backgroundColor = LineColor;
        cell.bottomLineImg.backgroundColor = LineColor;
        cell.topLineImg.height = 0.3;
        cell.topLineImg.width = kScreenWidth;
        cell.bottomLineImg.frame = CGRectMake(0, cell.height-0.5, kScreenWidth, 0.5);
        cell.FamilyDetialInfoLable.frame = CGRectMake(cell.FamilyTitleLable.right+10, 0, kScreenWidth - (cell.FamilyTitleLable.right+10) - viewLeft, cell.height);
        return cell;
    }
    //医生姓名|科室   跳转
    else if (indexPath.section == 1){
        FamilyMedicalRecordDoctorCell * cell = [tableView dequeueReusableCellWithIdentifier:@"DoctorCell"];
        if (cell == nil) {
            if (IPhone6Plus) {
                cell = [[[NSBundle mainBundle] loadNibNamed:@"FamilyMedicalRecordDoctorCell" owner:self options:nil] lastObject];
            }else{
                cell = [[[NSBundle mainBundle] loadNibNamed:@"FamilyMedicalRecordDoctorCell" owner:self options:nil] firstObject];
            }
        }
        [cell.FamilyDoctorImg setImageWithURL:[NSURL URLWithString:self.userCaseModel.avatar] placeholderImage:[UIImage imageNamed:@"医生默认.png"]];
        cell.FamilyDoctorImg.layer.masksToBounds = YES;
        cell.FamilyDoctorImg.layer.cornerRadius = 3;
        cell.FamilyDoctorNameLable.text = [NSString stringWithFormat:@"%@ | %@",self.userCaseModel.doctorname,self.userCaseModel.departmentname];
        cell.topLineImg.backgroundColor = LineColor;
        cell.bottomLineImg.backgroundColor = LineColor;
        cell.topLineImg.height = 0.3;
        cell.topLineImg.width = kScreenWidth;
        cell.bottomLineImg.frame = CGRectMake(0, cell.height-0.5, kScreenWidth, 0.5);
        cell.FamilyJumpImg.right = kScreenWidth - 15;
        if (IPhone6Plus) {
            cell.FamilyJumpImg.right = kScreenWidth - 20;
        }
        
        return cell;
    }
    //初诊/复诊 -- 列表
    else if (indexPath.section >1){
    
        FamilyMedicalVisitModal * visitModal = self.visitDataArray[indexPath.section-2];
        //标题 行cell
        if (indexPath.row == 0 || indexPath.row == 1 || indexPath.row == 3) {
            FamilyMedicalTitleCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ZeoOneThree"];
            if (cell == nil) {
                if (IPhone6Plus) {
                    cell = [[[NSBundle mainBundle] loadNibNamed:@"FamilyMedicalTitleCell" owner:self options:nil] lastObject];
                }else{
                    cell = [[[NSBundle mainBundle] loadNibNamed:@"FamilyMedicalTitleCell" owner:self options:nil] firstObject];
                }
            }
            cell.FamilyTimeBackView.right = kScreenWidth - 15;
            if (IPhone6Plus) {
                cell.FamilyTimeBackView.right = kScreenWidth - 20;
            }
            cell.FamilyTimeBackView.hidden = YES;
            if (indexPath.row == 0) {
                cell.FamilyTitleLable.text = @"就诊时间";
                cell.FamilyTimeBackView.hidden = NO;
                cell.timeLable.text = visitModal.clinictime;
                cell.bottomLineImg.hidden = YES;
                
            }
            if (indexPath.row == 1) {
                cell.FamilyTitleLable.text = @"患者问题";
                //
                cell.topLineImg.backgroundColor = LineColor;
                cell.topLineImg.height = 0.3;
                cell.bottomLineImg.backgroundColor = LineColor;
                cell.bottomLineImg.frame = CGRectMake(15, cell.height-0.5, kScreenWidth-15, 0.5);
                if (IPhone6Plus) {
                    cell.bottomLineImg.left = 20;
                    cell.topLineImg.left = 20;
                }
                cell.topLineImg.width = kScreenWidth-cell.topLineImg.left;

            }
            if (indexPath.row == 3) {
                cell.FamilyTitleLable.text = @"医生诊断";
                cell.topLineImg.backgroundColor = LineColor;
                cell.topLineImg.height = 0.3;

                
                if (IPhone6Plus) {
                    
                    cell.topLineImg.left = 20;
                    
                }
                cell.topLineImg.width = kScreenWidth-cell.topLineImg.left;

            }
            
            return cell;
        }
        //患者的问题描述
        else if (indexPath.row == 2){
        
            FamilyMedicalProblemCell * cell = [tableView dequeueReusableCellWithIdentifier:@"Problem"];
            if (cell == nil) {
                if (IPhone6Plus) {
                    cell = [[[NSBundle mainBundle] loadNibNamed:@"FamilyMedicalProblemCell" owner:self options:nil] lastObject];
                }else{
                    cell = [[[NSBundle mainBundle] loadNibNamed:@"FamilyMedicalProblemCell" owner:self options:nil] firstObject];
                }
            }
            
            cell.FamilyProblemLable.text = visitModal.medicalDescription;
            
            cell.FamilyProblemLable.tag = indexPath.section*10 + indexPath.row;
            cell.FamilyProblemLable.left = 15;
            cell.FamilyProblemLable.numberOfLines = 0;
            CGFloat cellHeight = 44;
            CGFloat font = 13;
            if (IPhone6Plus) {
                cell.FamilyProblemLable.left = 20;
                cell.FamilyProblemLable.width = kScreenWidth - 40;
                font = 15;
                cellHeight = 53;
                
            }
            CGFloat height = [self autosizeFontAndSizeForTextString:visitModal.medicalDescription WithLableWeight:cell.FamilyProblemLable.width AndTextFont:font];

            cell.FamilyProblemLable.height = height;
            if (cellHeight - 20 >=height) {
                cell.FamilyProblemLable.top = (cellHeight - height)/2.0;
                
            }else{
                cell.FamilyProblemLable.top = 13;
            }
        
            return cell;
        }
        //医生诊断结果
        else if(indexPath.row == 4){
            FamilyLastPicCell * cell = [tableView dequeueReusableCellWithIdentifier:@"FamilyLastPicCell"];
            CGFloat viewLeft = 15;
            CGFloat viewWeight = kScreenWidth - 2*viewLeft;
            CGFloat font = 13;
            CGFloat cellHeight = 44;
            if (cell == nil) {
                if (IPhone6Plus) {
                    cell = [[[NSBundle mainBundle] loadNibNamed:@"FamilyLastPicCell" owner:self options:nil] lastObject];
                    viewLeft = 20;
                    viewWeight = kScreenWidth - 2*viewLeft;
                    font = 15;
                    cellHeight = 53;
                }else{
                    cell = [[[NSBundle mainBundle] loadNibNamed:@"FamilyLastPicCell" owner:self options:nil] firstObject];
                }
            }
            UIImageView * topLine = [[UIImageView alloc] initWithFrame:CGRectMake(viewLeft, 0, kScreenWidth - viewLeft, 0.3)];
            [cell.contentView addSubview:topLine];
            topLine.backgroundColor = LineColor;
            cell.doctorResultLable.text =visitModal.diagnose;
            cell.doctorResultLable.tag = indexPath.section*10 + indexPath.row;
            cell.doctorResultLable.width = viewWeight;
            cell.doctorResultLable.numberOfLines = 0;
            CGFloat height = [self autosizeFontAndSizeForTextString:visitModal.diagnose WithLableWeight:cell.doctorResultLable.width AndTextFont:font];
            cell.doctorResultLable.frame = CGRectMake(viewLeft, 13, viewWeight, height);
            
            //没有图片
            if (visitModal.pic.count == 0) {
                
                if (cellHeight - 20 >=height) {
                    cell.doctorResultLable.top = (cellHeight - height)/2.0;
                    cell.bottomLineImg.frame = CGRectMake(0,cellHeight - 0.5, kScreenWidth, 0.5);
                    
                }else{
                    cell.doctorResultLable.top = 13;
                    cell.bottomLineImg.frame = CGRectMake(0,cell.doctorResultLable.bottom+12.5, kScreenWidth, 0.5);
                }
                cell.doctorResultPicBackView.hidden = YES;
                cell.bottomLineImg.backgroundColor = LineColor;
                
                
            }
            else{
                
                cell.doctorResultLable.top = 13;
                cell.doctorResultPicBackView.frame = CGRectMake(cell.doctorResultLable.left,cell.doctorResultLable.bottom+13, kScreenWidth-2*cell.doctorResultLable.left, 55);
                if (IPhone6Plus) {
                    cell.doctorResultPicBackView.height = 65;
                }
                
                for (NSInteger i = 0; i < visitModal.pic.count; i++) {
                    CGFloat inter = (cell.doctorResultPicBackView.width - 4*cell.doctorResultPicBackView.height)/3.0;
                    UIImageView * picImg = [[UIImageView alloc] initWithFrame:CGRectMake((cell.doctorResultPicBackView.height+inter)*i, 0, cell.doctorResultPicBackView.height, cell.doctorResultPicBackView.height)];
                    picImg.clipsToBounds = YES;
                    picImg.layer.cornerRadius = 3;
                    [picImg setImageWithURL:[NSURL URLWithString:visitModal.pic[i]] placeholderImage:[UIImage imageNamed:@"公用_默认图片.png"]];
                    [cell.doctorResultPicBackView addSubview:picImg];
                }
                cell.bottomLineImg.backgroundColor = LineColor;
                cell.bottomLineImg.frame = CGRectMake(0, cell.doctorResultPicBackView.bottom + 12.5, kScreenWidth, 0.5);
                
            }
            
            
            return cell;
            
         }
        else
        {
            return nil;
        }
    }
    //没有了
    else
    {
        return nil;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1 && indexPath.row == 0) {
        
        DocInfoViewController * docInfo = [[DocInfoViewController alloc] init];
        docInfo.doctoruid = self.userCaseModel.doctoruid;
        [self.navigationController pushViewController:docInfo animated:YES];
    }
}

#pragma mark Lable自适应高度
- (void)autosizeFontAndSize:(UILabel *)label withText:(NSString *)text
{
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:label.text];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:0];//调整行间距
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
    paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
    label.attributedText = attributedString;
    [label sizeToFit];
}

#pragma mark - 让tableview的最后一行cell显示出来
-(void)scrollToRowAtLastSecionWithLastIndexPathWithSection:(NSInteger)section
{
    //找到最后一个cell
    NSIndexPath *lastIndexPath = [NSIndexPath indexPathForRow:4 inSection:section];//制定第2段的坐标为1的cell->indexPath
    //让屏幕上滑到指定的一个cell完全显示出来
    [self.tableView scrollToRowAtIndexPath:lastIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}
/**
 *  计算一段文本字符串在给定宽的情况下所用高
 *
 *  @param text   一段文字
 *  @param weight 给定这个lable的宽
 *  @param font   文字的字体
 *
 *  @return 高
 */
-(CGFloat)autosizeFontAndSizeForTextString:(NSString*)text WithLableWeight:(CGFloat)weight AndTextFont:(CGFloat)font
{
    NSDictionary *attributeDic = @{NSFontAttributeName:[UIFont systemFontOfSize:font]};
    CGRect rect = [text boundingRectWithSize:CGSizeMake(weight, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading|NSStringDrawingTruncatesLastVisibleLine attributes:attributeDic context:nil];
    return rect.size.height;
}
@end
